<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
        :title="crud.status.title" width="800px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
        <!--  <el-form-item label="id">
            <el-input v-model="form.id" style="width: 400px;" />
          </el-form-item> -->
          <el-form-item label="工作岗位" prop="p1">
            <el-input v-model="form.p1" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="薪酬范围" prop="p2">
            <el-input v-model="form.p2" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="学历要求" prop="div1">
            <el-input v-model="form.div1" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="工作经验" prop="div2">
            <el-input v-model="form.div2" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="招聘人数" prop="div3">
            <el-input v-model="form.div3" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="工作地点" prop="div4">
            <el-input v-model="form.div4" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="截止时间" prop="div5">
            <el-date-picker v-model="form.div5" type="date" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="是否发布" prop="recStatus">
            <el-radio v-for="item in dict.is_enable" :key="item.id" v-model="form.recStatus"
              :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="岗位责职" prop="responsibility">
            <el-input :rows="6" v-model="form.responsibility" type="textarea" style="width: 400px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;"
        @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <!-- <el-table-column v-if="columns.visible('id')" prop="id" label="id" /> -->
        <el-table-column v-if="columns.visible('p1')" prop="p1" label="工作岗位" />
        <el-table-column v-if="columns.visible('p2')" prop="p2" label="薪酬范围" />
        <el-table-column v-if="columns.visible('div1')" prop="div1" label="学历要求" />
        <el-table-column v-if="columns.visible('div2')" prop="div2" label="工作经验" />
        <el-table-column v-if="columns.visible('div3')" prop="div3" label="招聘人数" />
        <el-table-column v-if="columns.visible('div4')" prop="div4" label="工作地点" />
        <el-table-column v-if="columns.visible('div5')" prop="div5" label="截止时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.div5) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('recStatus')" prop="recStatus" label="是否发布">
          <template slot-scope="scope">
            {{ dict.label.is_enable[scope.row.recStatus] }}
          </template>
        </el-table-column>
        <!-- <el-table-column v-if="columns.visible('responsibility')" prop="responsibility" label="岗位责职" /> -->
        <el-table-column v-permission="['admin','stiRecruit:edit','stiRecruit:del']" label="操作" width="150px"
          align="center">
          <template slot-scope="scope">
            <udOperation :data="scope.row" :permission="permission" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
  import crudStiRecruit from '@/api/website/stiRecruit'
  import CRUD, {
    presenter,
    header,
    form,
    crud
  } from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'
  import MaterialList from "@/components/material";

  // crud交由presenter持有
  const defaultCrud = CRUD({
    title: '招聘信息',
    url: 'api/stiRecruit',
    sort: 'id,desc',
    crudMethod: {
      ...crudStiRecruit
    }
  })
  const defaultForm = {
    id: null,
    p1: null,
    p2: null,
    div1: null,
    div2: null,
    div3: null,
    div4: null,
    div5: null,
    recStatus: null,
    responsibility: null
  }
  export default {
    name: 'Recruit',
    components: {
      pagination,
      crudOperation,
      rrOperation,
      udOperation,
      MaterialList
    },
    mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
    dicts: ['is_enable'],
    data() {
      return {

        permission: {
          add: ['admin', 'stiRecruit:add'],
          edit: ['admin', 'stiRecruit:edit'],
          del: ['admin', 'stiRecruit:del']
        },
        rules: {
          p1: [{
            required: true,
            message: '工作岗位不能为空',
            trigger: 'blur'
          }],
          p2: [{
            required: true,
            message: '薪酬范围不能为空',
            trigger: 'blur'
          }],
          div1: [{
            required: true,
            message: '学历要求不能为空',
            trigger: 'blur'
          }],
          div2: [{
            required: true,
            message: '工作经验不能为空',
            trigger: 'blur'
          }],
          div3: [{
            required: true,
            message: '招聘人数不能为空',
            trigger: 'blur'
          }],
          div4: [{
            required: true,
            message: '工作地点不能为空',
            trigger: 'blur'
          }],
          div5: [{
            required: true,
            message: '截止时间不能为空',
            trigger: 'blur'
          }],
          recStatus: [{
            required: true,
            message: '是否发布不能为空',
            trigger: 'blur'
          }],
          responsibility: [{
            required: true,
            message: '岗位责职不能为空',
            trigger: 'blur'
          }]
        }
      }
    },
    watch: {},
    methods: {
      // 获取数据前设置好接口地址
      [CRUD.HOOK.beforeRefresh]() {
        return true
      }, // 新增与编辑前做的操作
      [CRUD.HOOK.afterToCU](crud, form) {},
    }
  }
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
